package xmpp.androidpush.aidl;

import android.os.Parcel;
import android.os.Parcelable;

import org.jivesoftware.smack.packet.IqMessage;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.packet.Presence;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;

public class PushIqMessage implements Parcelable {

    private HashMap<String, String> propertys;
    private HashMap<String, String> extensions;
    private IqMessage msg;

    private ArrayList<PacketExtension> packetExtension ;



    public PushIqMessage(IqMessage msg) {

       this.msg=msg;
    }




    public Collection<String> getPropertyNames() {
        return this.getPropertys().keySet();
    }
    public Collection<String> getExtensionsNames() {
        return this.getExtensions().keySet();
    }
    public String getProperty(String name) {
        return (String) this.getPropertys().get(name);
    }

    private HashMap<String, String> getPropertys() {
        if (this.propertys == null) {
            this.propertys = new HashMap();
        }

        return this.propertys;
    }
    public ArrayList<PacketExtension> getPacketExtension() {
        if (this.packetExtension == null) {
            this.packetExtension = new ArrayList<>();
        }

        return this.packetExtension;
    }
    public void setProperty(String name, String value) {
        this.getPropertys().put(name, value);
    }

    public HashMap<String, String> getExtensions() {
        if (this.extensions == null) {
            this.extensions = new HashMap();
        }
        return this.extensions;
    }

    public void setExtension(String name, String value) {
        this.getExtensions().put(name, value);
    }

    public IqMessage toMessage() {
//        IqMessage imsg =msg;

//        Iterator var3 = this.getPropertyNames().iterator();
//        while (var3.hasNext()) {
//            String name = (String) var3.next();
//            imsg.setProperty(name, this.getProperty(name));
//        }
//        imsg.addExtensions(msg.getExtensions());
        return msg;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeSerializable(this.propertys);
        dest.writeSerializable(this.extensions);
        dest.writeList(this.packetExtension);
    }

    protected PushIqMessage(Parcel in) {
        this.propertys = (HashMap<String, String>) in.readSerializable();
        this.extensions = (HashMap<String, String>) in.readSerializable();
        this.msg = in.readParcelable(IqMessage.class.getClassLoader());
        this.packetExtension = new ArrayList<PacketExtension>();
        in.readList(this.packetExtension, PacketExtension.class.getClassLoader());
    }

    public static final Creator<PushIqMessage> CREATOR = new Creator<PushIqMessage>() {
        @Override
        public PushIqMessage createFromParcel(Parcel source) {
            return new PushIqMessage(source);
        }

        @Override
        public PushIqMessage[] newArray(int size) {
            return new PushIqMessage[size];
        }
    };
}
